/*
 * 本类作用：mina框架:数据编解码器工厂
 * 
 * 作者：袁小杰
 * 博客：http://blog.csdn.net/undoner
 * GIT：https://git.oschina.net/undoner
 * QQ：15137281
 * 
 */
package org.mina.server.codec;

import java.nio.charset.Charset;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

/**
 * 编解码器工厂
 * */
public class MsgCodecFactory implements ProtocolCodecFactory {
	
	private final MsgEncoder encoder;
	private final MsgDecoder decoder;
	
	public MsgCodecFactory(){
		this(Charset.defaultCharset());
	}
	
	public MsgCodecFactory(Charset charset){
		this.encoder = new MsgEncoder(charset);
		this.decoder = new MsgDecoder(charset);
	}

	public ProtocolDecoder getDecoder(IoSession session) throws Exception {
		return decoder;
	}

	public ProtocolEncoder getEncoder(IoSession session) throws Exception {
		return encoder;
	}

}
